//username and password validation
function nameAndPassVal() {
    var input = document.getElementsByClassName('nameAndPassVal');
    //username
    input[0].focus();
    input[0].onkeydown = input[0].onblur = input[0].onkeyup = function(){
	        input[0].value = input[0].value.replace(/[^A-Za-z0-9]+[^A-Za-z0-9\-\_]*[^A-Za-z0-9]/gi, "");
	    }
	//pass
    input[1].onkeydown = input[1].onblur = input[1].onkeyup = function(){
        input[1].value = input[1].value.replace(/[^A-Za-z0-9]+[^A-Za-z0-9\-\_]*[^A-Za-z0-9]/gi, "");
    }
    //passRep
    input[2].onkeydown = input[2].onblur = input[2].onkeyup = function(){
        input[2].value = input[2].value.replace(/[^A-Za-z0-9]+[^A-Za-z0-9\-\_]*[^A-Za-z0-9]/gi, "");
    }
}

//email validation
function mailVal(){
	var mail = document.getElementById('mail').value;
	var dot = document.getElementById('mail').search(".");
	console.log(dot);
	if(!(mail.search("."))) {
		document.getElementById('mail').value = 'Невалиден email';
		//delete error message when clicked
		document.getElementById('mail').onclick = function(){
			document.getElementById('mail').value = '';
		}
	}
}